#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        hash[0] = 1;

        int sum = 0, ret = 0;
        for (auto& x : nums)
        {
            sum += x;
            if (hash.count(sum - k))
                ret += hash[sum-k];
            ++hash[sum];
        }

        return ret;
    }
};

int main()
{
    vector<int> nums({ 1,1,1 });
    cout << Solution().subarraySum(nums, 2) << endl;

    return 0;
}

int main2()
{
    string str;
    getline(cin, str);

    string ret;
    int pos = str.rfind(' '), i = str.size() - 1;
    while (pos != string::npos)
    {
        ret += str.substr(pos+1, i - pos);
        ret += ' ';
        i = pos - 1;
        pos = str.rfind(' ', i);
    }
    pos = str.find(' ');
    ret += str.substr(0, pos);
    cout << ret << endl;

    return 0;
}

int main1()
{
    int n;
    cin >> n;
    vector<int> prices(n);
    for (int i = 0; i < n; ++i)
        cin >> prices[i];

    int ret = 0;
    for (int i = 0; i < n; ++i)
    {
        int j = i;
        while (j + 1 < n && prices[j + 1] > prices[j])
            ++j;
        ret += prices[j] - prices[i];
        i = j;
    }
    cout << ret << endl;

    return 0;
}